// eslint.config.cjs
const { resolve } = require("node:path");
const ts = require("@typescript-eslint/eslint-plugin");
const tsParser = require("@typescript-eslint/parser");

module.exports = [
  // 全局忽略文件
  {
    ignores: [
      "**/node_modules/**",
      "**/dist/**",
      "**/build/**",
      "**/coverage/**",
      "**/*.d.ts",
      "**/package-lock.json",
      "**/yarn.lock"
    ]
  },

  // TypeScript 文件规则
  {
    files: ["**/*.ts", "**/*.tsx"],
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        // __dirname 在 .cjs 中可用，自动指向当前目录
        project: [resolve(__dirname, "./tsconfig.json"), "./tsconfig.node.json"],
        tsconfigRootDir: __dirname,
        sourceType: "module"
      }
    },
    plugins: {
      "@typescript-eslint": ts
    },
    rules: {
      // 强制使用 import type
      "@typescript-eslint/consistent-type-imports": [
        "error",
        {
          prefer: "type-imports",
          fixStyle: "separate-type-imports" // 自动修复为单独 import type
        }
      ],

      // 其他推荐规则
      "@typescript-eslint/no-unused-vars": "error"
    }
  }
];
